﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpShare.Afp.Protocol.Security;

namespace SharpShare.Afp.Protocol.Handlers {
    internal class AfpLoginContinueRequestHandler : IAfpRequestHandler {
        public byte CommandCode {
            get { return 19; }
        }

        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) {
            requestStream.ReadUInt8(); // Padding

            short id = requestStream.ReadInt16();

            if (session.AuthenticationMethod == null) {
                // Server sending login continue without login first?
                return AfpResultCode.FPParamErr;
            }

            AfpUserAuthenticationResult result = session.AuthenticationMethod.ContinueAuthentication(session, id, requestStream);

            return result.Execute(session, responseStream);
        }
    }
}
